package com.ruoyi.web.controller.consume;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.consume.domain.GraftinglabelConsumeTemporary;
import com.ruoyi.consume.domain.SimpleConsume;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.GreenhousefilmConsumeTemporary;
import com.ruoyi.consume.service.IGreenhousefilmConsumeTemporaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查看临时领用信息Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("查看临时领用信息")
@RestController
@RequestMapping("/consume/greenhousefilmtemcon")
public class GreenhousefilmConsumeTemporaryController extends BaseController
{
    @Autowired
    private IGreenhousefilmConsumeTemporaryService greenhousefilmConsumeTemporaryService;

    /**
     * 查询查看临时领用信息列表
     */
    @ApiOperation("查询查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:list')")
    @GetMapping("/list")
    public TableDataInfo list(GreenhousefilmConsumeTemporary greenhousefilmConsumeTemporary)
    {
        startPage();
        List<GreenhousefilmConsumeTemporary> list = greenhousefilmConsumeTemporaryService.selectGreenhousefilmConsumeTemporaryList(greenhousefilmConsumeTemporary);
        return getDataTable(list);
    }

    /**
     * 导出查看临时领用信息列表
     */
    @ApiOperation("导出查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:export')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GreenhousefilmConsumeTemporary greenhousefilmConsumeTemporary)
    {
        List<GreenhousefilmConsumeTemporary> list = greenhousefilmConsumeTemporaryService.selectGreenhousefilmConsumeTemporaryList(greenhousefilmConsumeTemporary);
        ExcelUtil<GreenhousefilmConsumeTemporary> util = new ExcelUtil<GreenhousefilmConsumeTemporary>(GreenhousefilmConsumeTemporary.class);
        return util.exportExcel(list, "查看临时领用信息数据");
    }

    /**
     * 获取查看临时领用信息详细信息
     */
    @ApiOperation("获取查看临时领用信息详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:query')")
    @GetMapping(value = "/{greenhousefilmConsumeTemporaryId}")
    public AjaxResult getInfo(@PathVariable("greenhousefilmConsumeTemporaryId") Long greenhousefilmConsumeTemporaryId)
    {
        return AjaxResult.success(greenhousefilmConsumeTemporaryService.selectGreenhousefilmConsumeTemporaryById(greenhousefilmConsumeTemporaryId));
    }

    /**
     * 新增查看临时领用信息
     */
    @ApiOperation("新增查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:add')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GreenhousefilmConsumeTemporary greenhousefilmConsumeTemporary)
    {
        return toAjax(greenhousefilmConsumeTemporaryService.insertGreenhousefilmConsumeTemporary(greenhousefilmConsumeTemporary));
    }

    /**
     * 修改查看临时领用信息
     */
    @ApiOperation("修改查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:edit')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GreenhousefilmConsumeTemporary greenhousefilmConsumeTemporary)
    {
        return toAjax(greenhousefilmConsumeTemporaryService.updateGreenhousefilmConsumeTemporary(greenhousefilmConsumeTemporary));
    }

    /**
     * 删除查看临时领用信息
     */
    @ApiOperation("删除查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:remove')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{greenhousefilmConsumeTemporaryIds}")
    public AjaxResult remove(@PathVariable Long[] greenhousefilmConsumeTemporaryIds)
    {
        return toAjax(greenhousefilmConsumeTemporaryService.deleteGreenhousefilmConsumeTemporaryByIds(greenhousefilmConsumeTemporaryIds));
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:greenhousefilmtemcon:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<GreenhousefilmConsumeTemporary> list = greenhousefilmConsumeTemporaryService.getUserName();
        List<SimpleConsume> simpleConsumes = new ArrayList<>();
        for (GreenhousefilmConsumeTemporary greenhousefilmConsumeTemporary:list) {
            Long id = greenhousefilmConsumeTemporary.getUserId();
            String name = greenhousefilmConsumeTemporary.getUserName();
            SimpleConsume consume = new SimpleConsume(id,name);
            simpleConsumes.add(consume);
        }
        return getDataTable(simpleConsumes);
    }
}
